//package approval.dao;
//
//import java.io.IOException;
//import java.sql.CallableStatement;
//import java.sql.ResultSet;
//import java.sql.Types;
//import java.util.ArrayList;
//import javax.faces.bean.ManagedBean;
//import javax.faces.bean.ManagedProperty;
//import javax.faces.bean.SessionScoped;
//import javax.faces.context.FacesContext;
//import javax.faces.event.AjaxBehaviorEvent;
//import javax.servlet.http.HttpSession;
//import org.apache.commons.codec.DecoderException;
//
//import resource.pojo.Approvedoc;
//import resource.pojo.ListApprove;
//import model.util.UtilInitLang;
//import models.pojo.AcEliManager;
//import models.pojo.Employee;
//import models.util.MySqlDataAccessHelper;
//
//@ManagedBean(name = "approvalMain")
//@SessionScoped
//public class ApprovalMain {
//	
//	private int approvalPending;
//	private int approvalCompleted;
//	private int approvalRefused;
//	private int myApprovalPending;
//	private int myApprovalCompleted;
//	private int myApprovalStorageTemporary;
//	private int myApprovalRefused;
//	private int numberApprovalPending;
//	
//	private String strErrorDbClickDoc = "";
//	@ManagedProperty(value = "#{utilInitLang.getClassEntity()}")
//	private UtilInitLang utilInitLang;
//	private int dbRowIndex;
//	private int currentIndex;
//	private String scriptDbClickDoc;
//	private Approvedoc currentApprovedoc = null;
//	private ArrayList<Approvedoc> lstApprovalPending = new ArrayList<Approvedoc>();
//	private YourDocDAO yourDocDao;
//	private ArrayList<Approvedoc> lstApproving = new ArrayList<Approvedoc>();	
//	private ArrayList<Approvedoc> lstStorageTemporary = new ArrayList<Approvedoc>();
//	private ArrayList<ListApprove> allListApprove = new ArrayList<ListApprove>();
//	private ArrayList<Approvedoc> allDocSelect = new ArrayList<Approvedoc>();
//	private boolean check;
//
//	
//
//	MySqlDataAccessHelper mysqlHelper = new MySqlDataAccessHelper();	
//
//	public MySqlDataAccessHelper getMysqlHelper() {
//		return mysqlHelper;
//	}
//
//	public void setMysqlHelper(MySqlDataAccessHelper mysqlHelper) {
//		this.mysqlHelper = mysqlHelper;
//	}
//
//	public ApprovalMain() {
//
//	}
//	/*
//	public int getNumYourDocApprove() {
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance()
//				.getExternalContext().getSession(true);
//		mysqlHelper.open();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "select * from approvedoc where IDStatus=2 and not ISNULL(approvedoc.IDGroupApprove)";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}
//		return numYourDocApprove;
//	}	
//
//	public String gotodocWillApprove() throws IOException {
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		Object obj = ss.getAttribute("Employee");
//		String path = f.getExternalContext().getRequestContextPath();
//		AcEliManager eli = (AcEliManager) ss.getAttribute("accessDB");
//		if (obj != null) {
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/erp/docWillApprove");
//		} else
//			f.getExternalContext().redirect(
//					"/" + eli.getDatabaseName() + "/erp/welcome");
//		return "";
//	}
//	 */
//	
//	
//
//	private int numberApprovalCompleted(){
//		int num = 0;		
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM listapprove WHERE listapprove.IDStatus=5 and listapprove.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					num++;
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}		
//		return num;
//	}
//	
//	private int numberApprovalRefused(){
//		int num = 0;		
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM listapprove WHERE listapprove.IDStatus=3 and listapprove.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					num++;
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}		
//		return num;
//	}
//	
//	private int numberMyApprovalRefused(){
//		int num = 0;		
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM approvedoc WHERE approvedoc.IDStatus=3 and approvedoc.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					num++;
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}		
//		return num;
//	}
//	
//	private int numberMyApprovalCompleted(){
//		int num = 0;		
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM approvedoc WHERE approvedoc.IDStatus=1 and approvedoc.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					num++;
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}		
//		return num;
//	}
//	
//	private int numberMyApprovalPending(){
//		int num = 0;		
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM approvedoc WHERE approvedoc.IDStatus=2 and approvedoc.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					num++;
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}		
//		return num;
//	}
//	
//	private int numberMyApprovalStorageTemporary(){
//		int num = 0;		
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		lstStorageTemporary.clear();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM approvedoc WHERE ISNULL(approvedoc.IDGroupApprove) and approvedoc.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					num++;
//
//					Approvedoc ap = new Approvedoc(rs.getInt("IDApproveDoc"),
//							rs.getString("Tile"), rs.getString("Content"),
//							rs.getString("IDEmployee"),
//							rs.getString("IDGroupApprove"),
//							rs.getDate("Timecreate"), rs.getInt("IDStatus"),
//							rs.getInt("IDTypeDoc"), rs.getDate("TimeApprove"),
//							rs.getString("comment"), rs.getString("Description"));
//					lstStorageTemporary.add(ap);
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}		
//		return num;
//	}
//	
//	private boolean checkApproved(ArrayList<ListApprove> all, Employee em) {
//		
//				for (ListApprove lst1 : all) {
//				if (lst1.getiDStatus().intValue() == 5 || lst1.getiDStatus().intValue() == 2)
//							return false;
//				}
//					
//		return true;
//	}
//
//	private ArrayList<Approvedoc> getlstApprovalPending(){
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		lstApprovalPending.clear();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM approvedoc " +
//						"JOIN listapprove ON listapprove.IDGroupApprove = approvedoc.IDGroupApprove "+
//						"WHERE listapprove.IDStatus=4 AND listapprove.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					
//					Approvedoc app = new Approvedoc(rs.getInt("IDApproveDoc"), rs
//							.getString("Tile"), rs.getString("Content"), rs
//							.getString("IDEmployee"), rs
//							.getString("IDGroupApprove"), rs.getDate("Timecreate"),
//							rs.getInt("IDStatus"), rs.getInt("IDTypeDoc"), rs
//									.getDate("TimeApprove"), rs
//									.getString("comment"), rs
//									.getString("Description"));
//					
//					if (checkApproved(app.getGroupApprove().getAllListApprove(),em)){
//						lstApprovalPending.add(app);
//					}
//					
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}
//		return lstApprovalPending;
//	}
//	
//	public ArrayList<Approvedoc> getLstApproving() {
//		HttpSession ss = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
//		mysqlHelper.open();
//		ArrayList<Approvedoc> app = new ArrayList<Approvedoc>();
//		try {
//			Employee em = (Employee) ss.getAttribute("Employee");
//			if (em != null) {
//				String sql = "SELECT * FROM approvedoc " +
//						"JOIN listapprove ON listapprove.IDGroupApprove = approvedoc.IDGroupApprove "+
//						"WHERE (listapprove.IDStatus=5 or listapprove.IDStatus=1) AND listapprove.IDEmployee='"+em.getIdemployee()+"'";
//				ResultSet rs = mysqlHelper.executeQuery(sql);
//				while(rs.next()){
//					app.add(new Approvedoc(rs.getInt("IDApproveDoc"), rs
//							.getString("Tile"), rs.getString("Content"), rs
//							.getString("IDEmployee"), rs
//							.getString("IDGroupApprove"), rs.getDate("Timecreate"),
//							rs.getInt("IDStatus"), rs.getInt("IDTypeDoc"), rs
//									.getDate("TimeApprove"), rs
//									.getString("comment"), rs
//									.getString("Description")));
//				}
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			mysqlHelper.close();
//		}
//		return app;
//	}
//
//	private boolean checkApproved(ArrayList<ListApprove> all) {
//		for (ListApprove lst : all) {
//			if (lst.getStatus().getiDStatus() == 4)
//				return true;
//		}
//		return false;
//	}
//	
//	public void onDbClickEdit(){
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		Approvedoc ap = lstApprovalPending.get(currentIndex);
//		ss.setAttribute("documentSelected", ap);
//		ss.setAttribute("open","true");
//	}
//	
//	public void onDbClickDoc() {
//		FacesContext f = FacesContext.getCurrentInstance();
//		HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//		Object obj = ss.getAttribute("Employee");
//		if (obj != null) {
//			models.pojo.Employee em = (models.pojo.Employee) obj;
//			Approvedoc row = lstApprovalPending.get(this.getDbRowIndex());
//			String IDEm = row.getiDEmployee();
//			if (!em.getIdemployee().equalsIgnoreCase(IDEm)) {
//
//				setStrErrorDbClickDoc(getUtilInitLang().getErrPermissionEdit());
//				setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
//			} else {
//				if (checkApproved(row.getGroupApprove().getAllListApprove())) {
//					setStrErrorDbClickDoc(getUtilInitLang()
//							.getErrEditDocApproved());
//					setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
//				} else {
//
//					ss.setAttribute("Doc", row);
//					ss.setAttribute("BindingListReceiver", new Boolean(true));
//					ss.setAttribute("BindingCbGroup", new Boolean(true));
//					ss.setAttribute("BindingCbType", new Boolean(true));
//					String strLink = "RichFaces.ui.PopupPanel.hidePopupPanel('popup');openWin('/ERPApprove/changeOrder.jsf?id="
//							+ row.getiDApproveDoc()
//							+ "',750,660,'orderApprove');";
//					setScriptDbClickDoc(strLink);
//				}
//			}
//		} else {
//			setStrErrorDbClickDoc("Something Error!!!");
//			setScriptDbClickDoc("RichFaces.ui.PopupPanel.showPopupPanel('popup')");
//		}
//	}
//	
//	public void Approvel() throws DecoderException {
//
//			try{
//				mysqlHelper.open();	
//				FacesContext f = FacesContext.getCurrentInstance();
//				HttpSession ss = (HttpSession) f.getExternalContext().getSession(true);
//				Employee em = (Employee) ss.getAttribute("Employee");
//				Approvedoc app = (Approvedoc) ss.getAttribute("documentSelected");			
//				String sqlLst = "update listapprove set IDStatus=5,DateApprove=NOW() where IDEmployee='" + em.getIdemployee()+
//					"'and IDGroupApprove="+app.getGroupApprove().getIdGroupApprove();
//				mysqlHelper.executeUpdate(sqlLst);
//			} catch (Exception e) {
//				e.printStackTrace();
//			} finally {
//				mysqlHelper.close();
//			}	
//		
//	}
//	
//	public void clickDocApproving() {
//		if (getYourDocDao().getAllTempYourDocDelete().size() > 0)
//			getYourDocDao().getAllTempYourDocDelete().clear();
//		allListApprove.clear();
//		Approvedoc ap = lstApprovalPending.get(this.getCurrentIndex());
//		setCurrentApprovedoc(ap);
//		allListApprove.addAll(ap.getGroupApprove().getAllListApprove());
//
//	}
//	
//	public void selectDoc(AjaxBehaviorEvent e) {
////		FacesContext f = FacesContext.getCurrentInstance();
////		currentApprovedoc = (Approvedoc) e.getComponent().getAttributes()
////				.get("approvedoc");
////		setAllListApprove(currentApprovedoc.getGroupApprove().getAllListApprove());
//		Approvedoc ap = (Approvedoc) e.getComponent().getAttributes().get("approvedoc");
//			if (allDocSelect.contains(ap))
//				allDocSelect.remove(ap);
//			else
//				allDocSelect.add(ap);
//			setAllListApprove(ap.getGroupApprove().getAllListApprove());
//	}
//
//	
//	public void setLstApproving(ArrayList<Approvedoc> lstApproving) {
//		this.lstApproving = lstApproving;
//	}
//
//
//	public ArrayList<Approvedoc> getLstStorageTemporary() {
//		return lstStorageTemporary;
//	}
//
//	public void setLstStorageTemporary(ArrayList<Approvedoc> lstStorageTemporary) {
//		this.lstStorageTemporary = lstStorageTemporary;
//	}
//	
//	public int getApprovalCompleted() {
//		return numberApprovalCompleted();
//	}
//
//
//
//	public int getApprovalRefused() {
//		return numberApprovalRefused();
//	}
//
//	public int getMyApprovalCompleted() {
//		return numberMyApprovalCompleted();
//	}
//
//	public int getMyApprovalStorageTemporary() {
//		return numberMyApprovalStorageTemporary();
//	}
//
//	public int getMyApprovalRefused() {
//		return numberMyApprovalRefused();
//	}
//
//	public int getMyApprovalPending() {
//		return numberMyApprovalPending();
//	}
//
//	public ArrayList<Approvedoc> getLstApprovalPending() {
//		return getlstApprovalPending();
//	}
//	
//	public Approvedoc getCurrentApprovedoc() {
//		return currentApprovedoc;
//	}
//
//	public void setCurrentApprovedoc(Approvedoc currentApprovedoc) {
//		this.currentApprovedoc = currentApprovedoc;
//	}
//	
//	public ArrayList<ListApprove> getAllListApprove() {
//		if (lstApprovalPending.size() == 0)
//			allListApprove.clear();
//		else if (this.getCurrentApprovedoc() != null) {
//			if (getYourDocDao().contains(this.getCurrentApprovedoc()))
//				allListApprove.clear();
//		}
//		return allListApprove;
//	}
//
//	public void setLstApprovalPending(ArrayList<Approvedoc> lstApprovalPending) {
//		this.lstApprovalPending = lstApprovalPending;
//	}
//
//	public void setAllListApprove(ArrayList<ListApprove> allListApprove) {
//		this.allListApprove = allListApprove;
//	}
//	
//	public YourDocDAO getYourDocDao() {
//		return yourDocDao;
//	}
//
//	public void setYourDocDao(YourDocDAO yourDocDao) {
//		this.yourDocDao = yourDocDao;
//	}
//	public int getDbRowIndex() {
//		return dbRowIndex;
//	}
//
//	public void setDbRowIndex(int dbRowIndex) {
//		this.dbRowIndex = dbRowIndex;
//	}
//	public String getScriptDbClickDoc() {
//		return scriptDbClickDoc;
//	}
//
//	public void setScriptDbClickDoc(String scriptDbClickDoc) {
//		this.scriptDbClickDoc = scriptDbClickDoc;
//	}
//	public UtilInitLang getUtilInitLang() {
//		return utilInitLang;
//	}
//
//	public void setUtilInitLang(UtilInitLang utilInitLang) {
//		this.utilInitLang = utilInitLang;
//	}
//	
//	public String getStrErrorDbClickDoc() {
//		return strErrorDbClickDoc;
//	}
//
//	public void setStrErrorDbClickDoc(String strErrorDbClickDoc) {
//		this.strErrorDbClickDoc = strErrorDbClickDoc;
//	}
//	
//	public boolean isCheck() {
//		return check;
//	}
//
//	public void setCheck(boolean check) {
//		this.check = check;
//	}
//	
//	public int getCurrentIndex() {
//		return currentIndex;
//	}
//
//	public void setCurrentIndex(int currentIndex) {
//		this.currentIndex = currentIndex;
//	}
//	
//	public ArrayList<Approvedoc> getAllDocSelect() {
//		return allDocSelect;
//	}
//
//	public void setAllDocSelect(ArrayList<Approvedoc> allDocSelect) {
//		this.allDocSelect = allDocSelect;
//	}
//	
//	public int getNumberApprovalPending() {
//		numberApprovalPending = lstApprovalPending.size();		
//		return numberApprovalPending;
//	}
//
//	public void setNumberApprovalPending(int numberApprovalPending) {
//		this.numberApprovalPending = numberApprovalPending;
//	}
//}
